/*
 * name: mabel xu
 * date: october 15, 2007
 * filename: SuperLinkedList.java
 * description: special class (extends LinkedList) that provides extra methods for working with Strings as elements
 */

import java.util.*;		// allows working with LinkedLists, ListIterators, etc.

public class SuperLinkedList extends LinkedList		// adds extra stuff for working with "String" LinkedLists
{
	public SuperLinkedList()	// woot ... default constructor!
	{
		super();
	}		// end of default constructor

	// pre: superlinkedlist(sll) initialized, single-character-string passed
	// post: returns true or false depending on vowel or not
	// description: private method to make testing for vowels easier
	private static boolean isVowel(String s)
	{
		if (s.equals("A") || s.equals("a") ||
				s.equals("E") || s.equals("e") ||
				s.equals("I") || s.equals("i") ||
				s.equals("O") || s.equals("o") ||
				s.equals("U") || s.equals("u"))
			return true;
		else
			return false;
	}		// end of isVowel private method (my own addition)

	// pre: list initialized
	// post: list has no vowels, returns true if stuff were removed
	// description: goes through and removes all vowels, returns true if stuff removed
	public boolean removeVowels()
	{
		ListIterator iter = this.listIterator();
		boolean removed = false;
		while(iter.hasNext())		// go through entire list
		{
			String node = (String)(iter.next());
			if (isVowel(node))		// if there's any vowels ... remove it
			{
				iter.remove();
				removed = true;
			}		// end of checking if vowel
		}		// end of loop to traverse list
		return removed;
	}		// end of removeVowels method

	// pre: list initialized, if stuff are not vowels then they are automatically consonants
	// post: list has no consonants, returns true if stuff were removed
	// description: goes through and removes all consonants, returns true if stuff removed
	public boolean removeConsonants()
	{
		ListIterator iter = this.listIterator();
		boolean removed = false;
		while(iter.hasNext())		// go thorugh entire list
		{
			String node = (String)(iter.next());
			if (!isVowel(node))		// if there's any consonants ... remove it
			{
				iter.remove();
				removed = true;
			}		// end of checking if consonant
		}		// end of loop to traverse list
		return removed;
	}		// end of removeConsonants

	// pre: list initialized
	// post: keeps original list untouched, returns "concatenated" list
	// description: returns a list where each element is sum of previous elements ... kindof
	public LinkedList concatenateStrings()
	{
		ListIterator iter = this.listIterator();
		String temp = "";
		LinkedList result = new LinkedList();
		while(iter.hasNext())		// loop through entire list
		{
			temp += iter.next();
			result.add(temp);
		}		// end of loop to traverse through entire list
		return result;
	}		// end of concatenateStrings() method

	// pre: list initialized, another list of same length provided
	// post: keeps original unmodified, returns linkedlist mix
	// description: takes element from each list and adds to new list (mixes the two original lists)
	public LinkedList mix(LinkedList other)
	{
		ListIterator iter = this.listIterator();
		ListIterator iter2 = other.listIterator();
		LinkedList result = new LinkedList();
		while(iter.hasNext())		// go through entire list (both are same length)
		{
			result.add(iter.next());
			result.add(iter2.next());
		}		// end of loop to traverse both lists
		return result;
	}		// end of mix method

	// pre: list initialized
	// post: returns String representation of list
	// description: returns String representation of list, adding ", " between each element
	public String toString()
	{
		String temp = "";
		ListIterator iter = this.listIterator();
		while(iter.hasNext())		// go through entire list and add to string
			temp += (String)(iter.next()) + ", ";
		if (temp.length() > 0)		// if stuff added then get rid of ending ", "
			temp = temp.substring(0, temp.length() - 2);
		return temp;
	}		// end of toString method
}		// end of SuperLinkedList class